package com.qipay.baas.mapper;

import static org.apache.ibatis.jdbc.SqlBuilder.BEGIN;
import static org.apache.ibatis.jdbc.SqlBuilder.INSERT_INTO;
import static org.apache.ibatis.jdbc.SqlBuilder.SET;
import static org.apache.ibatis.jdbc.SqlBuilder.SQL;
import static org.apache.ibatis.jdbc.SqlBuilder.UPDATE;
import static org.apache.ibatis.jdbc.SqlBuilder.VALUES;
import static org.apache.ibatis.jdbc.SqlBuilder.WHERE;

import com.qipay.baas.model.Message;

public class MessageSqlProvider {

    public String insertSelective(Message record) {
        BEGIN();
        INSERT_INTO("message");
        
        if (record.getSendBy() != null) {
            VALUES("send_by", "#{sendBy,jdbcType=INTEGER}");
        }
        
        if (record.getSendName() != null) {
            VALUES("send_name", "#{sendName,jdbcType=VARCHAR}");
        }
        
        if (record.getReceiveBy() != null) {
            VALUES("receive_by", "#{receiveBy,jdbcType=INTEGER}");
        }
        
        if (record.getReceiveName() != null) {
            VALUES("receive_name", "#{receiveName,jdbcType=VARCHAR}");
        }
        
        if (record.getContent() != null) {
            VALUES("content", "#{content,jdbcType=VARCHAR}");
        }
        
        if (record.getStatus() != null) {
            VALUES("`status`", "#{status,jdbcType=TINYINT}");
        }
        
        if (record.getType() != null) {
            VALUES("`type`", "#{type,jdbcType=TINYINT}");
        }
        
        if (record.getCreateTime() != null) {
            VALUES("create_time", "#{createTime,jdbcType=TIMESTAMP}");
        }
        
        return SQL();
    }

    public String updateByPrimaryKeySelective(Message record) {
        BEGIN();
        UPDATE("message");
        
        if (record.getSendBy() != null) {
            SET("send_by = #{sendBy,jdbcType=INTEGER}");
        }
        
        if (record.getSendName() != null) {
            SET("send_name = #{sendName,jdbcType=VARCHAR}");
        }
        
        if (record.getReceiveBy() != null) {
            SET("receive_by = #{receiveBy,jdbcType=INTEGER}");
        }
        
        if (record.getReceiveName() != null) {
            SET("receive_name = #{receiveName,jdbcType=VARCHAR}");
        }
        
        if (record.getContent() != null) {
            SET("content = #{content,jdbcType=VARCHAR}");
        }
        
        if (record.getStatus() != null) {
            SET("`status` = #{status,jdbcType=TINYINT}");
        }
        
        if (record.getType() != null) {
            SET("`type` = #{type,jdbcType=TINYINT}");
        }
        
        if (record.getCreateTime() != null) {
            SET("create_time = #{createTime,jdbcType=TIMESTAMP}");
        }
        
        WHERE("id = #{id,jdbcType=INTEGER}");
        
        return SQL();
    }
}